<?php
/**
 * The view of doc module of ZenTaoPMS.
 *
 * @copyright   Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv11.html)
 * @author      Jia Fu <fujia@cnezsoft.com>
 * @package     doc
 * @version     $Id: view.html.php 975 2010-07-29 03:30:25Z jajacn@126.com $
 * @link        http://www.zentao.net
 */
?>
<?php include '../../../common/view/header.html.php';?>
<!--<link rel="stylesheet" href="--><?php //echo $themeRoot;?><!--zui/css/min.css" />-->
<link rel="stylesheet" href="<?php echo $jsRoot;?>editormd/css/editormd.preview.css" />

<script src='<?php echo $jsRoot;?>jquery/jquery.base64.js' type='text/javascript'></script>
<script src='<?php echo $jsRoot;?>jquery/jquery.base64.js' type='text/javascript'></script>
<script src='<?php echo $jsRoot;?>jquery/jquery.base64.js' type='text/javascript'></script>
<script src="<?php echo $jsRoot;?>editormd/lib/marked.min.js"></script>
<script src="<?php echo $jsRoot;?>editormd/lib/prettify.min.js"></script>

<script src="<?php echo $jsRoot;?>editormd/lib/raphael.min.js"></script>
<script src="<?php echo $jsRoot;?>editormd/lib/underscore.min.js"></script>
<script src="<?php echo $jsRoot;?>editormd/lib/sequence-diagram.min.js"></script>
<script src="<?php echo $jsRoot;?>editormd/lib/flowchart.min.js"></script>
<script src="<?php echo $jsRoot;?>editormd/lib/jquery.flowchart.min.js"></script>

<script src="<?php echo $jsRoot;?>editormd/editormd.js"></script>
<?php echo css::internal($keTableCSS);?>
<div id='titlebar'>
  <div class='heading'>
    <span class='prefix' title='DOC'><?php echo html::icon($lang->icons['doc']);?> <strong><?php echo $doc->id;?></strong></span>
    <strong><?php echo $doc->title;?></strong>
    <?php if($doc->deleted):?>
    <span class='label label-danger'><?php echo $lang->doc->deleted;?></span>
    <?php endif; ?>
  </div>
  <div class='actions'>
    <?php
    $browseLink = $this->session->docList ? $this->session->docList : inlink('browse');
    $params     = "docID=$doc->id";
    if(!$doc->deleted)
    {
        ob_start();
        echo "<div class='btn-group'>";
        common::printIcon('doc', 'edit', $params);
        common::printIcon('doc', 'delete', $params, '', 'button', '', 'hiddenwin');
        echo '</div>';
        echo "<div class='btn-group'>";
        common::printRPN($browseLink, $preAndNext);
        echo '</div>';
        $actionLinks = ob_get_contents();
        ob_end_clean();
        echo $actionLinks;
    }
    else
    {
        common::printRPN($browseLink);
    }
    ?>
  </div>
</div>
<div class='row-table'>
  <div class='col-main'>
    <div class='main'>
      <fieldset>
        <legend><?php echo $lang->doc->digest;?></legend>
        <div id="markdown-to-html-digest">
<!--            <textarea style="display: none;">--><?php //echo $doc->digest;?><!--</textarea>-->
           <?php echo $doc->digest;?>
        </div>
          <div id="custom-toc-digest"></div>
      </fieldset>
        <fieldset>
            <legend><?php echo $lang->doc->keywords;?></legend>
            <div>
                <?php  echo $doc->keywords;?>
            </div>
        </fieldset>
        <script>
//            $(function() {
//                editormd.markdownToHTML("markdown-to-html-digest", {
//                    markdown: $("#markdown-to-html-digest>textarea").text(),//+ "\r\n" + $("#append-test").text(),
//                    htmlDecode: true,       // 开启 HTML 标签解析，为了安全性，默认不开启
//                    htmlDecode: "style,script,iframe",  // you can filter tags decode
//                    //toc             : false,
//                    tocm: false,    // Using [TOCM]
//                    tocContainer: "#custom-toc-content", // 自定义 ToC 容器层
//                    //gfm             : false,
//                    //tocDropdown     : true,
//                    // markdownSourceCode : true, // 是否保留 Markdown 源码，即是否删除保存源码的 Textarea 标签
//                    emoji: true,
//                    taskList: true,
//                    tex: true,  // 默认不解析
//                    flowChart: true,  // 默认不解析
//                    sequenceDiagram: true,  // 默认不解析
//                });
//
////
////                    // 获取Markdown源码
////                    //console.log(testEditormdView.getMarkdown());
////
////                    //alert(testEditormdView.getMarkdown());
//            });
        </script>
      <?php if($doc->type == 'url'):?>
      <fieldset>
        <legend><?php echo $lang->doc->url;?></legend>
        <div><?php echo html::a(urldecode($doc->url), '', '_blank');?></div>
      </fieldset>
      <?php endif;?>
      <?php if($doc->type == 'text'):?>
          <style>
             /* #sidebar {
                  width: 400px;
                  height: 100%;
                  position: fixed;
                  top: 400px;
                  right: 0;
                  overflow: hidden;
                  background: #fff;
                  z-index: 100;
                  padding: 18px;
                  border: 1px solid #ddd;
                  border-top: none;
                  border-bottom: none;
              }

              #sidebar:hover {
                  overflow: auto;
              }

              #sidebar h1 {
                  font-size: 16px;
              }*/
          </style>
      <fieldset>
        <legend><?php echo $lang->doc->content;?></legend>
        <div class='content'>
            <div id="markdown-to-html-content">
                <textarea style="display:none;" id="content"><?php echo $doc->content;?></textarea>
            </div>
            <script type="text/javascript">
                $(function() {
                    var editormdView;

                    editormdView = editormd.markdownToHTML("markdown-to-html-content", {
                        markdown        : $("#markdown-to-html-content>textarea").text() ,//+ "\r\n" + $("#append-test").text(),
                        htmlDecode      : true,       // 开启 HTML 标签解析，为了安全性，默认不开启
                        htmlDecode      : "style,script,iframe",  // you can filter tags decode
                        //toc             : false,
                        tocm            : true,    // Using [TOCM]
                        tocContainer    : "#custom-toc-content", // 自定义 ToC 容器层
                        //gfm             : false,
                        //tocDropdown     : true,
                        // markdownSourceCode : true, // 是否保留 Markdown 源码，即是否删除保存源码的 Textarea 标签
                        emoji           : true,
                        taskList        : true,
                        tex             : true,  // 默认不解析
                        flowChart       : true,  // 默认不解析
                        sequenceDiagram : true,  // 默认不解析
                    });
                });
            </script>

        </div>
      </fieldset>
      <?php endif;?>
      <?php if($doc->type == 'file'):?>
      <?php echo $this->fetch('file', 'printFiles', array('files' => $doc->files, 'fieldset' => 'true'));?>
      <?php endif;?>
      <?php include '../../../common/view/action.html.php';?>
      <div class='actions'><?php if(!$doc->deleted) echo $actionLinks;?></div>
    </div>
  </div>
  <div class='col-side'>
    <div class='main main-side'>
      <fieldset>
        <legend><?php echo $lang->doc->basicInfo;?></legend>
        <table class='table table-data table-condensed table-borderless table-fixed'>
         <tr>
            <th class='w-60px'><?php echo $lang->doc->lib;?></th>
            <td><?php echo $lib;?></td>
          </tr>
          <tr>
            <th><?php echo $lang->doc->module;?></th>
            <td><?php echo $doc->moduleName ? $doc->moduleName : '/';?></td>
          </tr>
          <tr>
            <th><?php echo $lang->doc->type;?></th>
            <td><?php echo $lang->doc->types[$doc->type];?></td>
          </tr>
          <tr>
            <th><?php echo $lang->doc->addedBy;?></th>
            <td><?php echo $users[$doc->addedBy];?></td>
          </tr>
          <tr>
            <th><?php echo $lang->doc->addedDate;?></th>
            <td><?php echo $doc->addedDate;?></td>
          </tr>
          <tr>
            <th><?php echo $lang->doc->editedBy;?></th>
            <td><?php echo $users[$doc->editedBy];?></td>
          </tr>
          <tr>
            <th><?php echo $lang->doc->editedDate;?></th>
            <td><?php echo $doc->editedDate;?></td>
          </tr>
        </table>
      </fieldset>
    </div>
      <div class="main main-side">
          <fieldset>
              <legend>目录结构</legend>
              <div class="markdown-body editormd-preview-container" id="custom-toc-content">#custom-toc-container</div>
          </fieldset>
      </div>
  </div>
</div>
<?php include '../../../common/view/syntaxhighlighter.html.php';?>
<?php include '../../../common/view/footer.html.php';?>
